﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MathNet.Numerics.Distributions;
using MentalAlchemy.Molecules;

namespace MentalAlchemy.Compounds
{
	public class Utils
	{
		/// <summary>
		/// [compounds]
		/// 
		/// Returns user-defined Poisson distribution. The distribution parameters are defined using set of windows.
		/// </summary>
		/// <returns></returns>
		public static RandomDistribution GetPoissonDistribution ()
		{
			var inputForm = new FloatInputForm();
			inputForm.Text = "Enter lambda value";
			inputForm.LabelText = "Enter lambda value";
			inputForm.NumericCntrl.Value = 1;
			inputForm.NumericCntrl.Minimum = (decimal)0.1;
			var inRes = inputForm.ShowDialog();
			if (inRes != DialogResult.OK) return null;
			var lambda = (float)inputForm.NumericValue;

			var dDistr = new DiscreteRandomDistribution();
			dDistr.Distribution = new PoissonDistribution(lambda);
			return dDistr;
		}

		/// <summary>
		/// [compounds]
		/// 
		/// Returns user-defined Gaussian distribution. The distribution parameters are defined using set of windows.
		/// </summary>
		/// <returns></returns>
		public static RandomDistribution GetGaussianDistribution()
		{
			var inputForm = new FloatInputForm();
			inputForm.Text = "Enter mean value";
			inputForm.LabelText = "Enter mean value";
			inputForm.NumericCntrl.Value = 0;
			var inRes = inputForm.ShowDialog();
			if (inRes != DialogResult.OK) return null;
			var mean = (float)inputForm.NumericValue;

			inputForm.Text = "Enter sigma value";
			inputForm.LabelText = "Enter sigma value";
			inputForm.NumericCntrl.Value = 1;
			inRes = inputForm.ShowDialog();
			if (inRes != DialogResult.OK) return null;
			var sigma = (float)inputForm.NumericValue;

			var cDistr = new ContinuousRandomDistribution();
			cDistr.Distribution = new NormalDistribution(mean, sigma);
			return cDistr;
		}

		/// <summary>
		/// [compounds]
		/// 
		/// Returns user-defined geometric distribution. The distribution parameters are defined using set of windows.
		/// </summary>
		/// <returns></returns>
		public static RandomDistribution GetGeometricDistribution()
		{
			var inputForm = new FloatInputForm();
			inputForm.Text = "Enter success probability";
			inputForm.LabelText = "Enter success probability";
			inputForm.NumericCntrl.Value = (decimal)0.5;
			inputForm.NumericCntrl.Minimum = (decimal)0.1;
			var inRes = inputForm.ShowDialog();
			if (inRes != DialogResult.OK) return null;
			var sp = (float)inputForm.NumericValue;

			var cDistr = new DiscreteRandomDistribution();
			cDistr.Distribution = new GeometricDistribution(sp);
			return cDistr;
		}

		/// <summary>
		/// [compounds]
		/// 
		/// Returns user-defined uniform distribution. The distribution parameters are defined using set of windows.
		/// </summary>
		/// <returns></returns>
		public static RandomDistribution GetUniformDistribution()
		{
			var inputForm = new FloatInputForm();
			inputForm.Text = "Enter mean value";
			inputForm.LabelText = "Enter mean value";
			inputForm.NumericCntrl.Value = 0;
			var inRes = inputForm.ShowDialog();
			if (inRes != DialogResult.OK) return null;
			var mean = (float)inputForm.NumericValue;

			inputForm.Text = "Enter sigma value";
			inputForm.LabelText = "Enter sigma value";
			inputForm.NumericCntrl.Value = 1;
			inRes = inputForm.ShowDialog();
			if (inRes != DialogResult.OK) return null;
			var sigma = (float)inputForm.NumericValue;

			var cDistr = new ContinuousRandomDistribution();
			cDistr.Distribution = new ContinuousUniformDistribution(mean, sigma);
			return cDistr;
		}
	}
}
